loadstring(exports.dgs:dgsImportFunction())()
local sw,sh = guiGetScreenSize()
local px,py = sw/1366,sh/768
font = dgsCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 16*px )

local replaces = {
	{model = 132, file = 'Heros-WielkaStopa',},
	{model = 133, file = 'Heros-PiesPunkto',},
	{model = 134, file = 'Heros-ZabojczyKrolik',},
	{model = 135, file = 'Heros-StraznikPystyniKhazix',},
	{model = 136, file = 'Heros-HandlarzMirek',},
}

for i,v in pairs(replaces) do
    local txd = engineLoadTXD (""..v["file"]..".txd")
    engineImportTXD (txd, v["model"])
    local dff = engineLoadDFF (""..v["file"]..".dff")
    engineReplaceModel (dff, v["model"])
end

addCommandHandler("gp2",function()
    local x,y,z = getElementPosition(localPlayer)
    local xr,yr,zr = getElementRotation(localPlayer)
    p=string.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",x,y,z,xr,yr,zr)
    setClipboard(p)
end)

addEventHandler( "onClientResourceStart", resourceRoot,function ()
    for i,ped in pairs(getElementsByType("ped")) do
        local x,y,z = getElementPosition(ped)
        if getElementData(ped,"HerosID") == 1 then 
            text1 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text1)
            dgs3DTextAttachToElement(text1,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        elseif getElementData(ped,"HerosID") == 2 then 
            text2 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text2)
            dgs3DTextAttachToElement(text2,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        elseif getElementData(ped,"HerosID") == 3 then 
            text3 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text3)
            dgs3DTextAttachToElement(text3,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        elseif getElementData(ped,"HerosID") == 4 then 
            text4 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text4)
            dgs3DTextAttachToElement(text4,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        elseif getElementData(ped,"HerosID") == 5 then 
            text5 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text5)
            dgs3DTextAttachToElement(text5,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        elseif getElementData(ped,"HerosID") == 6 then 
            text6 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
            setElementData(ped,"textHeros",text6)
            dgs3DTextAttachToElement(text6,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
        end
    end
end)

addEvent("cmta_herosi:stworztext", true)
addEventHandler("cmta_herosi:stworztext", root, function(ped)
    local x,y,z = getElementPosition(ped)
    if getElementData(ped,"HerosID") == 1 then 
        text1 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text1)
        dgs3DTextAttachToElement(text1,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    elseif getElementData(ped,"HerosID") == 2 then 
        text2 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text2)
        dgs3DTextAttachToElement(text2,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    elseif getElementData(ped,"HerosID") == 3 then 
        text3 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text3)
        dgs3DTextAttachToElement(text3,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    elseif getElementData(ped,"HerosID") == 4 then 
        text4 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text4)
        dgs3DTextAttachToElement(text4,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    elseif getElementData(ped,"HerosID") == 5 then 
        text5 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text5)
        dgs3DTextAttachToElement(text5,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    elseif getElementData(ped,"HerosID") == 6 then 
        text6 = dgsCreate3DText(x,y,z,getElementData(ped,"Heros"),tocolor(153,50,204,255),font,0.4,0.4,25,true)
        setElementData(ped,"textHeros",text6)
        dgs3DTextAttachToElement(text6,ped,0,0,tonumber(getElementData(ped,"HerosTextHeight")))
    end
end)


addEvent("cmta_herosi:usuntext", true)
addEventHandler("cmta_herosi:usuntext", root, function(ped)
    if ped == 1 then 
        destroyElement(text1)
    elseif ped == 2 then 
        destroyElement(text2)
    elseif ped == 3 then 
        destroyElement(text3)
    elseif ped == 4 then 
        destroyElement(text4)
    elseif ped == 5 then 
        destroyElement(text5)
    elseif ped == 6 then 
        destroyElement(text6)
    end
end)